package com.haixiaoke.saas.manage.lock.controller;

import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.lock.domain.LockFace;
import com.haixiaoke.saas.lock.service.ILockFaceService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 锁人脸授权Controller
 *
 * @author panda
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/manage/lock/lockFace")
public class ManageLockFaceController extends BaseController {
    @Autowired
    private ILockFaceService lockFaceService;

    /**
     * 查询锁人脸授权列表
     */
    @GetMapping("/page")
    public TableDataInfo page(LockFace lockFace) {
        if (lockFace.getLockId() == null) {
            return getDataTable("请选择锁");
        }
        startPage();
        List<LockFace> list = lockFaceService.selectLockFaceList(lockFace);
        return getDataTable(list);
    }

    /**
     * 查询锁人脸授权列表
     */
    @GetMapping("/list")
    public AjaxResult list(LockFace lockFace) {
        List<LockFace> list = lockFaceService.selectLockFaceList(lockFace);
        return success(list);
    }

    /**
     * 获取锁人脸授权详细信息
     */
    @GetMapping(value = "/{faceId}")
    public AjaxResult getInfo(@PathVariable("faceId") Long faceId) {
        return success(lockFaceService.selectLockFaceByFaceId(faceId));
    }

    /**
     * 新增锁人脸授权
     */
    @PostMapping
    public AjaxResult add(@RequestBody LockFace lockFace) {
        lockFace.setCreateBy(getUsername());
        return lockFaceService.manageInsertLockFace(lockFace);
    }

    /**
     * 修改锁的主管理员
     */
    @PutMapping("/mainAdmin")
    public AjaxResult mainAdmin(@RequestBody LockFace lockFace) {
        return lockFaceService.updateLockMainAdmin(lockFace, null);
    }

    /**
     * 删除锁人脸授权
     */
    @DeleteMapping("/{faceId}")
    public AjaxResult remove(@PathVariable Long faceId) {
        return lockFaceService.deleteLockFaceByFaceId(faceId, null, getUsername());
    }


    /**
     * 获取用户关联的设备列表
     */
    @GetMapping(value = "/user")
    public TableDataInfo relevanceDevice(LockFace lockFace) {
        startPage();
        return getDataTable(lockFaceService.userIdRelevanceDevice(lockFace));
    }
}
